package com.lxw.report.meta.vo;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

public class ResultVo<T> implements Serializable{
    @ApiModelProperty(value = "错误编号 200：调用成功， 500：服务器错误 401：会话失效")
    private String code;

    @ApiModelProperty(value = "错误信息")
    private String message;

    @ApiModelProperty(value = "错误位置")
    private String position;

    private T data;

    public ResultVo(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultVo(String code, String message, String position, T data) {
        this.code = code;
        this.message = message;
        this.position = position;
        this.data = data;
    }

    public ResultVo(T data) {
        this("200","success", data);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static ResultVo success() {
        return new ResultVo<>(null);
    }

    public static ResultVo success(Object data) {
        return new ResultVo<Object>(data);
    }

    public static ResultVo fail() {
        return fail("fail");
    }

    public static ResultVo fail(String message) {
        return new ResultVo("500", message, null);
    }

    public static ResultVo fail(String message, String position) {
        return new ResultVo("500", message,position, null);
    }

    public static ResultVo failLogin(String message) {
        return new ResultVo("401", message, null);
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }
}
